package com.lancoo.edu.platform.operation.commons.config;

import com.lancoo.edu.platform.operation.commons.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器路径配置
 *
 * @author pky
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    /**
     * 配置拦截路径
     *
     * @param registry 拦截器参考
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // token 拦截所有请求，通过判断是否有 @CheckToken 注解 决定是否需要校验
        registry
                .addInterceptor(tokenInterceptor())
                .addPathPatterns("/**");
    }

    /**
     * token 拦截器注入
     *
     * @return Token 拦截器
     */
    @Bean
    public TokenInterceptor tokenInterceptor() {
        return new TokenInterceptor();
    }

}
